import Vue from 'vue'
import Vuex from 'vuex'

import {
  flowRunTaskQuery,
  flowApiSubmit,
  flowHisTaskQuery,
  flowApiTakeBack,
  flowApiTurnDown,
  flowApiComplete,
  flowApiQueryCurrentFlowInfo,
  flowApiQueryInstanceList,
} from '@/api/admin/audit/flowApi.js'

Vue.use(Vuex)

const state = {}

const getters = {}

const actions = {
  //查询流程
  async queryFlowRunTask({ commit }, listQuery) {
    let res = await flowRunTaskQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //历史流程接口
  async queryFlowHisTask({ commit }, listQuery) {
    let res = await flowHisTaskQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //提交审核 - 用户
  async submitFlowApi({ commit }, data) {
    let res = await flowApiSubmit(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //提交审核 - 审核人审核
  async completeFlowApi({ commit }, data) {
    let res = await flowApiComplete(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //创建人取回
  async takeBackFlowRunTask({ commit }, data) {
    let res = await flowApiTakeBack(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //审核人驳回
  async turnDownFlowRunTask({ commit }, data) {
    let res = await flowApiTurnDown(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //查询当前流程的状态
  async queryCurrentFlowInfoFlowApi({ commit }, data) {
    let res = await flowApiQueryCurrentFlowInfo(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //流程监控
  async queryInstanceListFlowApi({ commit }, listQuery) {
    let res = await flowApiQueryInstanceList({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
}

const mutations = {}

export default {
  state,
  getters,
  actions,
  mutations,
}
